using System;

namespace NET.Library.Manipulation
{
	/// <summary>
	/// Strings Manipulation Object.
	/// </summary>
	public class Strings
	{
		/// '---------------------------------------------------------------------------------------------------------------------
		/// 'Remove invalid characters from strings to stop script and sql injection attacks.
		/// '---------------------------------------------------------------------------------------------------------------------
		public static string RemoveInvalidChar(string Value)
		{
			string strRemInvalidChar;

			if (Value==null)
			{
				return Value;
			}
			else
			{
				strRemInvalidChar = Value.Trim();
                strRemInvalidChar = strRemInvalidChar.Replace(",", ""); //'Removes comma
				strRemInvalidChar = strRemInvalidChar.Replace(Convert.ToString((char)34), ""); // 'Removes double qoute
				strRemInvalidChar = strRemInvalidChar.Replace("'", ""); // 'Removes single quote
                strRemInvalidChar = strRemInvalidChar.Replace(";", ""); //Removes semi-colon
                strRemInvalidChar = strRemInvalidChar.Replace("--", ""); //Removes comment delimiter
                strRemInvalidChar = strRemInvalidChar.Replace("/*", ""); //Removes comment delimiter
                strRemInvalidChar = strRemInvalidChar.Replace("*/", ""); //Removes comment delimiter
                strRemInvalidChar = strRemInvalidChar.Replace("xp_", ""); //Used at the start of the name of catalog-extended stored procedures, such as xp_cmdshell.
				return strRemInvalidChar;
			}
		}

		/// '-----------------------------------------------------------------------------------------
		/// 'returns string values 
		/// '-----------------------------------------------------------------------------------------
		public static string stringGetValue(object Value)
		{
			return Value == DBNull.Value ? String.Empty : Value.ToString();
		}

        /// '-----------------------------------------------------------------------------------------
        /// <summary>
        /// Checks for an empty string
        /// </summary>
        /// <param name="Value"></param>
        /// <returns></returns>
        /// '-----------------------------------------------------------------------------------------
        public static bool IsEmptyString(string Value)
        {
            return RemoveInvalidChar(Value).Length == 0 ? true : false;
        }

        /// '-----------------------------------------------------------------------------------------
        /// <summary>
        /// Reverses a given string
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        /// '-----------------------------------------------------------------------------------------
        public static string ReverseString(string value)
        {
            string reverseValue = "";

            for (int i = 0; i < value.Length; i++)
            {
                reverseValue+=(value[value.Length - i - 1]);
            }

            return reverseValue;

        }
	}
}
